package controller

import (
	"github.com/gin-gonic/gin"
	_redis "github.com/go-redis/redis"
	"go.uber.org/zap"
	"gorm.io/gorm"
	"net/http"
	"shorturl/global"
	"shorturl/log"
)

type BaseController struct{}

var db *gorm.DB
var redis *_redis.Client
var logger *zap.Logger

func init() {
	db = global.Db
	redis = global.Redis
	logger = log.Logger
}

// Success 成功返回
func (app BaseController) Success(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "success",
		"data": data,
	})
}

// Error 错误返回
func (app BaseController) Error(c *gin.Context, msg string) {
	c.JSON(http.StatusOK, gin.H{
		"code": 500,
		"msg":  msg,
	})
}
